<?php include_once('king_head.php');
if($action=="Save")
{//echo '***NUM='.$num;
$dqr="delete from site_addon where site_id=".$_SESSION['SITE_ID'];
mysql_query($dqr);
$k=0;
	for($k=1; $k<$num; $k++)
	{
			$qry="INSERT INTO site_addon(product_id, site_id, addon_id, Active) values(".${'product_id'.$k}.", $_SESSION['SITE_ID'],". ${'addon_id'.$k}.", '".${'active'.$k}."')";
			mysql_query($qry);
			//echo $qry;
	}
	echo"<h4><font color='red'>Updated Sucessfully!!</font></h4>";
}
?>
				    <h2>Add On Pricing</h2>
					<form name="frm" method="post" action="addon_pricing.php?site_id=<?php echo $_SESSION['SITE_ID'];?>">
					<table width="484" border="1" align="center">
<?php
$i=1;
$q="select * from site_product where site_id=".$_SESSION['SITE_ID'];
$r=mysql_query($q);
while($row=mysql_fetch_array($r))//WHILE 1
{
?>
  <tr>
    <TH width="137"><div align="left">Product</div></TH>
    <TH width="331"><div align="left">Product Code</div></TH>
  </tr>
  <tr>
    <td><?php echo $row['product_title'];?></td>
    <td><?php echo $row['product_id'];?></td>
  </tr>   
  <!--<tr><td colspan="2"><hr color="#FFFFFF" size="2"/></td></tr>-->
  <tr><td colspan="2">   
 <?php
 $q1="select * from product_addon where product_id=".$row['product_id'];
 $r1=mysql_query($q1);?>
  <table width="100%" border="1">
  <tr><td colspan="5"> Addons for this Product</td></tr>
  <tr>
    <TH width="93">Active</TH>
    <TH width="91">Addon Id</TH>
    <TH width="138">Title</TH>
    <!--<TH>QTY</TH>
    <TH>Increase</TH>
    <TH>QTY</TH>
    <TH>Increase</TH>
    <TH>QTY</TH>
    <TH>Increase</TH>
    <TH>QTY</TH>
    <TH>Increase</TH>
    <TH>QTY</TH>
    <TH>Increase</TH>
    <TH>QTY</TH>
    <TH>Increase</TH>-->
  </tr>
 <?php 
 while($row1=mysql_fetch_array($r1))//WHILE 2
 {
 if($row1['product_id']!=""){//IF 1
 $qq="select active from site_addon where site_id=".$_SESSION['SITE_ID']." and addon_id=".$row1['addon_id'];
// echo $qq.'###########';
 $rr=mysql_query($qq);
 $row2=mysql_fetch_array($rr);
 ?>
  <tr>
    <td><input type="hidden" name="product_id<?php echo $i;?>" value="<?php echo $row1['product_id'];?>" /> <input type="checkbox" name="active<?php echo $i;?>" <?php if($row2['active']=='Y')echo 'checked';?> value="Y" /></td>
    <td><?php echo $row1['addon_id'];?><input type="hidden" name="addon_id<?php echo $i;?>" value="<?php echo $row1['addon_id'];?>" /></td>
    <td><?php echo $row1['addon_title'];?><input type="hidden" name="addon_title<?php echo $i;?>" value="<?php echo $row1['addon_title'];?>" /></td><!--
    <td><input name="slot1<?php //echo $i;?>" type="text" value="<?php //echo $row1['slot1'];?>" size="10" /></td>
    <td><input name="pr_inc1<?php //echo $i;?>" type="text" value="<?php //echo $row1['pr_inc1'];?>" size="10" />  </td>
    <td><input name="slot2<?php //echo $i;?>" type="text" value="<?php //echo $row1['slot2'];?>" size="10" /></td>
    <td><input name="pr_inc2<?php //echo $i;?>" type="text" value="<?php //echo $row1['pr_inc2'];?>" size="10" /></td>
    <td><input name="slot4<?php //echo $i;?>" type="text" value="<?php //echo $row1['slot3'];?>" size="10" /></td>
    <td><input name="pr_inc3<?php //echo $i;?>" type="text" value="<?php //echo $row1['pr_inc3'];?>" size="10" /></td>
    <td><input name="slot4<?php //echo $i;?>" type="text" value="<?php //echo $row1['slot4'];?>" size="10" /></td>
    <td><input name="pr_inc4<?php //echo $i;?>" type="text" value="<?php //echo $row1['pr_inc4'];?>" size="10" /></td>
    <td><input name="slot5<?php //echo $i;?>" type="text" value="<?php //echo $row1['slot5'];?>" size="10" /></td>
    <td><input name="pr_inc5<?php //echo $i;?>" type="text" value="<?php //echo $row1['pr_inc5'];?>" size="10" /></td>
    <td><input name="slot6<?php //echo $i;?>" type="text" value="<?php //echo $row1['slot6'];?>" size="10" /></td>
    <td><input name="pr_inc6<?php //echo $i;?>" type="text" value="<?php //echo $row1['pr_inc6'];?>" size="10" /></td>-->
  </tr>
 <?php }//IF 1
 $i++;
 }//WHILE 2 
 ?>
 <tr>
   <td><input type="hidden" name="num" value="<?php echo $i;?>" /></td>
 </tr> 
 <!--<tr><td colspan="15"><hr color="#FFFFFF" size="2"/></td></tr>-->
 </table>
 <?php
 }//WHILE 1
 ?> 
 </td></tr>
 <tr><td colspan="3"> <div align="center">
   <input type="submit" value="Save" name="action" />
 </div>
 </table>
  </form>                  
 <?php include_once('king_foot.php');?>